package com.bw.lib_common.livedata_eventbus

import androidx.lifecycle.MutableLiveData

/**
 * @author ytx
 * @date 2025-09-19 15:34
 * @description
 */
object LiveDataEventBus {
    private val bus = mutableMapOf<String,MutableLiveData<*>>() //所有livedata

    fun <T> with(key:String,type:Class<T>):MutableLiveData<T>{
        if (!bus.contains(key)){
            bus[key] = MutableLiveData<T>()
        }
        return bus[key] as MutableLiveData<T>
    }

    /**
     * 发送事件
     */
    fun <T> postEvent(key:String,value:T){
        with(key,value!!::class.java).value = value
    }



}